import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
 
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list:[]
  },
  mutations: {
    initData(state,list){
      state.list = list
    },
    chageState(state,id){
      state.list.forEach(item=>{
        if(item.id==id){
          item.done=!item.done
        }
      })
    }
  },
  // 异步
  actions: {
    getDataFromInternet({commit}){
      axios.get('data.json').then(res=>{
        commit('initData',res.data.list)
        console.log(res)
      }).catch(err=>{
        console.log(err)
      })
    }
  },
  modules: {
  }
})
